//
// Created by LinorInk on 2024/5/13.
//

#ifndef SPIDER_RT_ACTIONS_H
#define SPIDER_RT_ACTIONS_H
#include "stm32f407xx.h"
#include "dr16.h"
#define ACTION_SERVO_NUM 19

typedef struct {
    uint8_t count;      // 记录帧数量
    uint8_t index;      // 记录帧索引
    uint16_t (*action)[ACTION_SERVO_NUM];  // 记录帧动作
    uint16_t *tick;      // 记录帧时长
    uint32_t last_update_tick;
}action_controller_t;

static uint16_t action_idle[ACTION_SERVO_NUM] = {160, 170, 140, 145, 55, 95, 175, 160, 215, 145, 65, 240, 135, 130, 75, 170, 150, 195};

static uint16_t action_idle_high[ACTION_SERVO_NUM] = {170, 110, 100, 150, 120, 160, 162, 215, 170, 145, 135, 185, 130, 210, 140, 165, 215, 145};

static uint16_t action_idle_short[ACTION_SERVO_NUM] = {220, 160, 140, 180, 65, 95, 140, 155, 230, 90, 75, 240, 105, 145, 75, 140, 160, 210};

static uint16_t action_idle_down[ACTION_SERVO_NUM] = {220,195,140,180,35,95,140,120,230,90,30,240,105,100,75,140,110,210};

static uint16_t action_walk[][ACTION_SERVO_NUM] = {         {155, 160, 155, 165, 60, 90, 175, 150, 240, 120, 70, 250, 145, 145, 70, 150, 155, 210},
                                                            {180, 165, 155, 135, 30, 90, 140, 150, 235, 155, 50, 240, 105, 130, 55, 180, 125, 215},
                                                            {180, 160, 150, 135, 70, 100, 140, 165, 230, 155, 90, 230, 105, 145, 65, 180, 165, 200},
                                                            {155, 190, 160, 165, 60, 95, 175, 140, 230, 120, 80, 235, 145, 120, 65, 150, 160, 210},

};
static uint16_t action_walk_tick[] = {70,70,70,70};

action_controller_t action_walk_controller = {
    .index = 0,
    .count = 4,
    .action = action_walk,
    .tick = action_walk_tick
};

static uint16_t action_turn_round_right[][ACTION_SERVO_NUM] = {{190,210,168,150,39,83,125,120,241,116,54,250,140,110,65,132,147,206},
                                                              {190,190,168,150,39,83,125,140,241,116,54,250,140,130,65,132,147,206},
                                                              {150,190,168,180,19,83,175,140,241,176,34,250,120,130,65,192,117,206},
                                                              {150,190,168,180,39,83,175,140,241,176,54,250,120,130,65,192,147,206}
};
static uint16_t action_turn_round_right_tick[] = {80,80,80,80};

action_controller_t action_turn_round_right_controller = {
        .index = 0,
        .count = 4,
        .action = action_turn_round_right,
        .tick = action_turn_round_right_tick
};

static uint16_t action_turn_round_left[][ACTION_SERVO_NUM] = {{150,210,168,180,39,83,175,120,241,176,54,250,110,110,65,192,147,206},
                                                               {150,182,168,180,39,83,175,140,241,176,54,250,110,130,65,192,147,206},
                                                               {190,182,168,140,19,83,115,140,241,116,34,250,150,130,65,132,117,206},
                                                               {190,182,168,140,39,83,115,140,241,116,54,250,150,130,65,132,147,206}
};
static uint16_t action_turn_round_left_tick[] = {80,80,80,80};

action_controller_t action_turn_round_left_controller = {
        .index = 0,
        .count = 4,
        .action = action_turn_round_left,
        .tick = action_turn_round_left_tick
};

static uint16_t action_move_left[][ACTION_SERVO_NUM] =       {{170, 170, 150, 155, 70, 110, 155, 150, 235, 146, 60, 260, 135, 140, 70, 162, 150, 215},
                                                              {170, 190, 150, 155, 50, 80, 155, 130, 230, 146, 70, 230, 135, 135, 55, 162, 155, 200},
                                                              {170, 160, 130, 155, 50, 80, 155, 175, 195, 146, 70, 230, 135, 135, 60, 162, 155, 200},
                                                              {170, 170, 150, 155, 30, 110, 155, 150, 235, 146, 60, 260, 135, 155, 100, 162, 150, 215}
};
static uint16_t action_move_left_tick[] = {80,80,80,80};

action_controller_t action_move_left_controller = {
        .index = 0,
        .count = 4,
        .action = action_move_left,
        .tick = action_move_left_tick
};

static uint16_t action_move_right[][ACTION_SERVO_NUM] =       {{170, 170, 170, 150, 50, 90, 155, 145, 255, 146, 70, 250, 130, 155, 105, 162, 150, 206},
                                                              {170, 160, 140, 150, 50, 70, 155, 155, 220, 146, 50, 230, 130, 140, 65, 162, 130, 196},
                                                              {170, 160, 140, 150, 60, 75, 155, 160, 220, 146, 75, 220, 130, 140, 65, 162, 170, 175},
                                                               {170, 170, 170, 150, 80, 120, 155, 145, 255, 146, 70, 250, 130, 120, 80, 162, 150, 210}
};
static uint16_t action_move_right_tick[] = {80,80,80,80};

action_controller_t action_move_right_controller = {
        .index = 0,
        .count = 4,
        .action = action_move_right,
        .tick = action_move_right_tick

};

static uint16_t action_back[][ACTION_SERVO_NUM] =             {{175, 160, 150, 135, 65, 90, 145, 165, 230, 160, 70, 250, 120, 155, 80, 185, 160, 210},
                                                               {155, 165, 145, 165, 45, 90, 165, 155, 240, 130, 50, 240, 145, 150, 80, 155, 135, 215},
                                                               {155, 175, 160, 165, 65, 95, 170, 150, 240, 130, 70, 240, 140, 135, 70, 155, 155, 210},
                                                               {180, 180, 140, 135, 65, 100, 145, 145, 240, 160, 75, 240, 110, 140, 90, 185, 155, 210}
};
static uint16_t action_back_tick[] = {50,50,50,50};

action_controller_t action_back_controller = {
        .index = 0,
        .count = 4,
        .action = action_back,
        .tick = action_back_tick
};

static uint16_t action_turn_round_left_high[][ACTION_SERVO_NUM] = {{190, 210, 168, 120, 120, 160, 125, 120, 241, 116, 135, 185, 150, 110, 65, 132, 215, 145},
                                                              {190, 110, 100, 120, 120, 160, 125, 215, 170, 116, 135, 185, 150, 210, 140, 132, 215, 145},
                                                              {150, 110, 100, 180, 19, 83, 175, 215, 170, 176, 34, 250, 120, 210, 140, 192, 210, 150},
                                                              {150, 110, 100, 180, 120, 160, 175, 215, 170, 176, 135, 185, 120, 210, 140, 192, 215, 145}
};
static uint16_t action_turn_round_left_high_tick[] = {100,100,100,100};

action_controller_t action_turn_round_left_high_controller = {
        .index = 0,
        .count = 4,
        .action = action_turn_round_left_high,
        .tick = action_turn_round_left_high_tick
};

static uint16_t action_turn_round_right_high[][ACTION_SERVO_NUM] =  {{150, 210, 168, 180, 120, 160, 175, 120, 241, 176, 135, 185, 110, 110, 65, 192, 215, 145},
                                                                   {150, 110, 100, 180, 120, 160, 175, 215, 170, 176, 135, 185, 110, 210, 140, 192, 215, 145},
                                                                   {190, 110, 100, 120, 19, 83, 115, 215, 170, 116, 34, 250, 150, 210, 140, 132, 117, 206},
                                                                   {190, 110, 100, 120, 120, 160, 115, 215, 170, 116, 135, 185, 150, 210, 140, 132, 215, 145}
};
static uint16_t action_turn_round_right_high_tick[] = {100,100,100,100};

action_controller_t action_turn_round_right_high_controller = {
        .index = 0,
        .count = 4,
        .action = action_turn_round_right_high,
        .tick = action_turn_round_right_high_tick
};
// origin
static uint16_t action_cheer[][ACTION_SERVO_NUM] =  {{165, 155, 140, 150, 30, 175, 175, 170, 230, 145, 80, 240, 135, 170, 150, 180, 160, 210},
                                                     {165, 155, 140, 150, 95, 175, 175, 170, 230, 145, 80, 240, 135, 105, 150, 180, 160, 210},
};


//my change
// static uint16_t action_cheer[][ACTION_SERVO_NUM] =  {{165, 155, 140, 150, 30, 175, 175, 170, 230, 145, 80, 240, 135, 170, 150, 180, 160, 210},
// //                                                       {165, 155, 140, 150, 95, 175, 175, 170, 230, 145, 80, 240, 135, 105, 150, 180, 160, 210},};
static uint16_t action_cheer_tick[] = {200,200};

action_controller_t action_cheer_controller = {
        .index = 0,
        .count = 2,
        .action = action_cheer,
        .tick = action_cheer_tick
};

static uint16_t action_cheer_1[][ACTION_SERVO_NUM] =  { {165, 155, 140, 150, 30, 175, 175, 170, 230, 145, 80, 240, 135, 170, 150, 180, 160, 210},
                                                        {165, 155, 140, 150, 95, 175, 175, 170, 230, 145, 80, 240, 135, 105, 150, 180, 160, 210},
                                                        {165, 155, 140, 150, 0, 165, 175, 170, 230, 145, 80, 240, 135, 90, 160, 180, 160, 210},
                                                        {165, 155, 140, 150, 0, 115, 175, 170, 230, 145, 80, 240, 135, 90, 110, 180, 160, 210},
};

static uint16_t action_cheer_1_tick[] = {120,120,120,120};

action_controller_t action_cheer_1_controller = {
        .index = 0,
        .count = 4,
        .action = action_cheer_1,
        .tick = action_cheer_1_tick
};
#endif //SPIDER_RT_ACTIONS_H
